package com.gem.talkbase.activity;



import com.gem.talkbase.bean.ChatMsg;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

public abstract class MyActivity extends Activity{

	private BroadcastReceiver MsgReceiver = new BroadcastReceiver() {

		@Override
		public void onReceive(Context context, Intent intent) {
			System.out.println("QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ");
			//Intent接收对象（里面包含多个属性）
			ChatMsg msg = (ChatMsg) intent
					.getSerializableExtra("message");
			if (msg != null) {//如果不是空，说明是消息广播
		
				getMessage(msg);// 把收到的消息传递给子类
			} else {//如果是空消息，说明是关闭应用的广播
//				close();
			}
		}

	};
	public abstract void getMessage(ChatMsg msg);
	
//	public void close() {
//		Intent i = new Intent();
//		i.setAction("com.gem.talkbase");
//		sendBroadcast(i);
//		finish();
//	}

	@Override
	public void onStart() {// 在start方法中注册广播接收者
		super.onStart();
		System.out.println("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
		IntentFilter intentFilter = new IntentFilter();
		intentFilter.addAction("com.gem.talkbase");
		registerReceiver(MsgReceiver, intentFilter);// 注册接受消息广播

	}

	@Override
	protected void onStop() {// 在stop方法中注销广播接收者
		super.onStop();
		unregisterReceiver(MsgReceiver);// 注销接受消息广播
	}
	
}
